<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Electron发送系统通知</title>
</head>
<body>
    <style>
        button {
            color: #ffffff;
            background-color: #44A1F8;
            font-size: 20px;
            outline: none;
        }

    </style>
    <button id="btn1">点击我,可以触发系统通知</button>
    <script>
        const path = require('path');
        const {shell} = require('electron')



        
        if(window.Notification) { 

            if(window.Notification.permission == "granted") {
                var notification = new Notification('你有一条新信息', {
                    body: "你好我是王小婷",
                    icon: "img/1.jpg"
                });
                setTimeout(function() { notification.close(); }, 5000);

            } else {
                window.Notification.requestPermission();
            }

        }


        document.getElementById("btn1").addEventListener('click', function(){

            let option = {
                title: "你订阅的《海贼王》更新了",
                body: "《海贼王》已更新至第852集 激斗开幕 路飞VS卡塔库栗",
                //icon: "../static/hhw.ico",
                href: 'https://www.iqiyi.com/v_19rqz6uit0.html'
            };
            console.log(option)

            // 创建通知并保存
            let hhwNotication = new window.Notification(option.title, option);

            console.log(hhwNotication)

            // 当通知被点击时, 用默认浏览器打开链接
            hhwNotication.onclick= function(){
                shell.openExternal(option.href)
            }

        })


    </script>
</body>
</html>